// $Id: test_types.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2008-2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */


#define BOOST_TEST_MODULE test_types
#include <cstddef>
#include <boost/type_traits.hpp>
#include <boost/test/unit_test.hpp>
#include <xpcom/types.hpp>

namespace
{

template <typename T>
bool test_type(const T&, std::size_t size, bool is_signed)
{
    return sizeof(T) == size && boost::is_signed<T>::value == is_signed;
}

}

#define TEST_TYPE(T, size, is_signed) test_type(T(), size, is_signed)

BOOST_AUTO_TEST_CASE(test_basic_types)
{
    using namespace xpcom;

    BOOST_CHECK(TEST_TYPE(int8_t, 1, true));
    BOOST_CHECK(TEST_TYPE(uint8_t, 1, false));
    BOOST_CHECK(TEST_TYPE(int16_t, 2, true));
    BOOST_CHECK(TEST_TYPE(uint16_t, 2, false));
    BOOST_CHECK(TEST_TYPE(int32_t, 4, true));
    BOOST_CHECK(TEST_TYPE(uint32_t, 4, false));
    BOOST_CHECK(TEST_TYPE(int64_t, 8, true));
    BOOST_CHECK(TEST_TYPE(uint64_t, 8, false));
    BOOST_CHECK(TEST_TYPE(int_t, sizeof(int), true));
    BOOST_CHECK(TEST_TYPE(uint_t, sizeof(unsigned), false));
    BOOST_CHECK(TEST_TYPE(bool_t, sizeof(int), true));
    BOOST_CHECK(TEST_TYPE(pbool_t, 1, true));
    BOOST_CHECK(TEST_TYPE(result_t, 4, false));
    BOOST_CHECK(TEST_TYPE(refcnt_t, 4, false));

    BOOST_CHECK_EQUAL(sizeof(wchar), 2U);
    BOOST_CHECK_EQUAL(sizeof(unichar), 4U);

    if (sizeof(wchar_t) == 2) {
        BOOST_CHECK((boost::is_same<wchar, wchar_t>::value));
    } else if (sizeof(wchar_t) == 4) {
        BOOST_CHECK((boost::is_same<unichar, wchar_t>::value));
    }

    BOOST_CHECK((boost::is_same<xpcom::size_t, std::size_t>::value));
}
